package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.MissionItemFeedbackAddDTO;
import org.jsola.hr.dto.MissionItemFeedbackUpdateDTO;
import org.jsola.hr.entity.MissionItemFeedbackDO;
import org.jsola.hr.query.MissionItemFeedbackQuery;
import org.jsola.hr.service.IMissionItemFeedbackService;
import org.jsola.hr.vo.MissionItemFeedbackVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 任务调度中心子项反馈记录
 *
 * @author zhr
 */
@Component
public class MissionItemFeedbackTestHelper extends BaseTestHelper {
    
    @Autowired
    private IMissionItemFeedbackService missionItemFeedbackService;

    /**
     * 生成add测试数据
     * @return MissionItemFeedbackAddDTO
     */
    public MissionItemFeedbackAddDTO getMissionItemFeedbackAddDTO(){
        MissionItemFeedbackAddDTO missionItemFeedbackAddDTO = new MissionItemFeedbackAddDTO();
        missionItemFeedbackAddDTO.setMissionItemId(getRandomValue("varchar",32));
        missionItemFeedbackAddDTO.setState(SafeKit.getInteger(getRandomValue("int",1)));
        missionItemFeedbackAddDTO.setFeedbackContent(getRandomValue("varchar",255));
        return missionItemFeedbackAddDTO;
    }


    /**
     * 生成update测试数据
     * @return MissionItemFeedbackUpdateDTO
     */
    public MissionItemFeedbackUpdateDTO getMissionItemFeedbackUpdateDTO(MissionItemFeedbackVO missionItemFeedbackVO){
        return missionItemFeedbackService.selectDOById(missionItemFeedbackVO.getId(), SITE_ID).to(MissionItemFeedbackUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return MissionItemFeedbackQuery
     */
    public MissionItemFeedbackQuery getMissionItemFeedbackQuery() {
        MissionItemFeedbackQuery missionItemFeedbackQuery = new MissionItemFeedbackQuery();
        List<MissionItemFeedbackDO> missionItemFeedbackDOList = missionItemFeedbackService.list(new MissionItemFeedbackDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(missionItemFeedbackDOList)) {
            MissionItemFeedbackDO missionItemFeedbackDO = missionItemFeedbackDOList.get(0);
            missionItemFeedbackQuery = missionItemFeedbackDO.to(MissionItemFeedbackQuery.class);
        }
        return missionItemFeedbackQuery;
    }

    /**
     * 保存示例
     * @return MissionItemFeedbackVO
     */
    public MissionItemFeedbackVO saveMissionItemFeedbackExample(){
        MissionItemFeedbackAddDTO addDTO = this.getMissionItemFeedbackAddDTO();
        MissionItemFeedbackVO missionItemFeedbackVO = missionItemFeedbackService.save(addDTO,buildTokenUser());
        return missionItemFeedbackVO;
    }


}

